﻿
@{
    ViewData["Title"] = "WarehouseAddIndex";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layer/skin/layer.css" rel="stylesheet" />
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">产品编码</label>
            <div class="layui-input-block">
                <input type="text" id="snCode" name="snCode" lay-verify="required" placeholder="请输入产品编码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">产品名称</label>
            <div class="layui-input-block">
                <input type="text" id="snName" name="snName" lay-verify="required" placeholder="请输入产品名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">规格型号</label>
            <div class="layui-input-block">
                <input type="text" id="models" name="models" lay-verify="required" placeholder="请输入规格型号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">单位</label>
            <div class="layui-input-block">
                <input type="text" id="unit" name="unit" lay-verify="required" placeholder="请输入单位" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">批次号</label>
            <div class="layui-input-block">
                <input type="text" id="batchCode" name="batchCode" lay-verify="required" placeholder="请输入批次号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">SN码数量</label>
            <div class="layui-input-block">
                <input type="text" id="snNum" name="snNum" lay-verify="required" placeholder="请输入SN码数量 autocomplete="off" class="layui-input">
            </div>
        </div>





        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <button type="reset" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
            </div>
        </div>
    </form>

    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/layui/layui.js"></script>
    <script src="~/layer/layer.js"></script>

    <script>
        layui.use(['form', 'laydate', 'util'], function(){
          var form = layui.form;
          var layer = layui.layer;
          var laydate = layui.laydate;
          var util = layui.util;

           // 页面加载完成后执行的函数
        $(function () {
            $('#primaryUnit').val(1);
        });

        function toggleDiv(value) {
              var additionalDiv = document.getElementById("additionalDiv");
              if (value === "是") {
                  additionalDiv.style.display = "block"; // 显示DIV
              } else {
                  additionalDiv.style.display = "none"; // 隐藏DIV
              }
          }

          // 提交事件
          form.on('submit(demo1)', function(data){
              console.log(data);
            var field = data.field; // 获取表单字段值
            // 显示填写结果，仅作演示用
            // layer.alert(JSON.stringify(field), {
            //   title: '当前填写的字段值'
            // });
            // 此处可执行 Ajax 等操作
            // …
            console.log(field);
        
            $.ajax({
                url:'/Warehouse/AddSNData',
                type:'post',
                data:field,
                dataType:'json',
                success:function(res){
                    if(res.code==1){
                        layer.alert('添加成功！')
                        closeWorkstation();
                    }
                    if(res.code==-100){
                         layer.alert('已经有此单位名称！')

                    }
                }
            })
            return false; // 阻止默认 form 跳转
          });
        });

        //关闭弹框
        function closeWorkstation() {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前的索引
            parent.layer.close(index); //再执行关闭
        }
    </script>

</body>
</html>

